<?php

include_once($_SERVER["DOCUMENT_ROOT"]. "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"]. "/include/user/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/mblog/inc.php");
$g_cgival = array();
$g_show = array();
$g_pro = array();

if(! security_check::check_refer())
{
	throw new Exception("来路不明");
}

function check_cgi_pro()
{
	global $g_cgival, $g_show, $g_pro;
	cgi::both($g_cgival['t'],"t","json");
	$g_cgival['t'] = string::un_html($g_cgival['t']);

	cgi::both($g_cgival['mid'],"mid","");
	$g_cgival['mid'] = string::un_html($g_cgival['mid']);
	
		
	
}


function get_data()
{
	global $g_cgival, $g_show, $g_pro;
	
	$mid = $g_cgival['mid'];
	
	$user_info = new user_info();
	$is_login = $user_info->is_logined();
	if($is_login)
	{
		$user_detail_info = $user_info->get_cur_user_info();
		
		$uid = $user_detail_info["uid"];
		$user_nickname = $user_detail_info["user_nickname"];
		
		
	}
	else
	{
		
		throw new Exception("未登录");
	}	
	
	$mod_mblog = new mod_mblog();
	$db_mblog_rt_mid = new db_mblog_rt_mid();
	$res = $db_mblog_rt_mid->get_item_by_mid($mid);
	
	if(!$res)
	{
		throw new Exception("需要抓取的微博ID不存在，请先添加！");
	}
	//抓取新的转发数据
	$mod_mblog->get_new_rt_count_by_mid($mid);
	
	$mod_mblog->update_rt_count_by_mid($mid);
	
	if(!$res)
	{
		throw new Exception("数据库操作失败");
	}
}

 
try
{
	check_cgi_pro();
	get_data();

	$g_show["error"] = "0";
	$g_show["errmsg"] = "操作成功";
}
catch (Exception $e)
{
	$g_show["error"] = "1";
	$g_show["errmsg"] = $e->getMessage();
}
show_pro();
exit();


function show_pro()
{
	global $g_cgival, $g_show, $g_pro;
	

	if($g_cgival['cb'])
	{
		header("Location:".$g_cgival['cb']."?pic_source={$g_show["pic_path"]}&pic={$g_show["pic_path1"]}&pic_name={$g_show["pic_name"]}&size={$g_show["size"]}&form_id={$g_show["form_id"]}&error={$g_show["error"]}&errormsg=".urlencode($g_show["errmsg"]));
	}
	else 
	{
		echo output::json($g_cgival["t"], $g_show, $g_cgival["callback"]);
	}
}